home *** CD-ROM | disk | FTP | other *** search
- /* MPEGSTAT - analyzing tool for MPEG-I video streams
- *
- * Technical University of Berlin, Germany, Dept. of Computer Science
- * Tom Pfeifer - Multimedia systems project - pfeifer@fokus.gmd.de
- *
- * Jens Brettin, Harald Masche, Alexander Schulze, Dirk Schubert
- *
- * This program uses parts of the source code of the Berkeley MPEG player
- *
- * ---------------------------
- *
- * Copyright (c) 1993 Technical University of Berlin, Germany
- *
- * for the parts of the Berkeley player used:
- *
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
- *
- * ---------------------------
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notices and the following
- * two paragraphs appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA
- * or the Technical University of Berlin BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA and the Technical University of Berlin
- * SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
- * UNIVERSITY OF CALIFORNIA and the Technical University of Berlin HAVE NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
- */
-
- /* MAIN.C CHANGED FOR MPEG ANALYZER, 1993 */
-
- #include "video.h"
- #include "proto.h"
- #include <sys/types.h>
- #include <signal.h>
- #ifndef MIPS
- #ifndef DOS
- #include <netinet/in.h>
- #endif
- #else
- #include <bsd/netinet/in.h>
- #endif
-
- #include "util.h"
-
- /* Define buffer length. */
-
- #define BUF_LENGTH 80000
-
- /* Function return type declarations */
- void usage();
-
- /* External declaration of main decoding call. */
-
- extern VidStream *mpegVidRsrc();
- extern VidStream *NewVidStream();
-
- /* Declaration of global variable to hold dither info. */
-
- int ditherType;
-
- /* Global file pointer to incoming data. */
- FILE *input;
-
- /* more global objects */
-
- int LUM_RANGE;
- int CR_RANGE;
- int CB_RANGE;
-
- int *lum_values;
- int *cr_values;
- int *cb_values;
-
- /* End of File flag. */
- static int EOF_flag = 0;
-
- /* Loop flag. */
- int loopFlag = 0;
-
- /* Shared memory flag. */
- int shmemFlag = 0;
-
- /* Quiet flag. */
- int quietFlag = 0;
-
- /* Display image on screen? */
- int noDisplayFlag = 0;
-
- /* Setjmp/Longjmp env. */
- jmp_buf env;
-
-
-
- /*
- *--------------------------------------------------------------
- *
- * get_more_data --
- *
- * Called by correct_underflow in bit parsing utilities to
- * read in more data.
- *
- * Results:
- * Input buffer updated, buffer length updated.
- * Returns 1 if data read, 0 if EOF, -1 if error.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-
- int
- get_more_data(buf_start, max_length, length_ptr, buf_ptr)
- unsigned int *buf_start;
- int max_length;
- int *length_ptr;
- unsigned int **buf_ptr;
- {
-
- int length, num_read, i, request;
- unsigned char *buffer, *mark;
- unsigned int *lmark;
-
- if (EOF_flag) return 0;
-
- length = *length_ptr;
- buffer = (unsigned char *) *buf_ptr;
-
- if (length > 0) {
- memcpy((unsigned char *) buf_start, buffer, (length*4));
- mark = ((unsigned char *) (buf_start + length));
- }
- else {
- mark = (unsigned char *) buf_start;
- length = 0;
- }
-
- request = (max_length-length)*4;
-
-
- num_read = fread( mark, 1, request, input);
-
- byte_count(num_read);
-
- /* Paulo Villegas - 26/1/1993: Correction for 4-byte alignment */
- {
- int num_read_rounded;
- unsigned char *index;
-
- num_read_rounded = 4*(num_read/4);
-
- /* this can happen only if num_read<request; i.e. end of file reached */
- if( num_read_rounded < num_read )
- {
- num_read_rounded = 4*( num_read/4+1 );
- /* fill in with zeros */
- for( index=mark+num_read; index<mark+num_read_rounded; *(index++)=0 );
- /* advance to the next 4-byte boundary */
- num_read = num_read_rounded;
- }
- }
-
- if (num_read < 0) {
- return -1;
- }
- else if (num_read == 0) {
- *buf_ptr = buf_start;
-
- /* Make 32 bits after end equal to 0 and 32
- bits after that equal to seq end code
- in order to prevent messy data from infinite
- recursion.
- */
-
- *(buf_start + length) = 0x0;
- *(buf_start + length+1) = SEQ_END_CODE;
-
- EOF_flag = 1;
- return 0;
- }
-
- lmark = (unsigned int *) mark;
-
- num_read = num_read/4;
-
- for (i=0; i<num_read; i++) {
- *lmark = htonl(*lmark);
- lmark++;
- }
-
- *buf_ptr = buf_start;
- *length_ptr = length + num_read;
-
- return 1;
- }
-
- /*
- *--------------------------------------------------------------
- *
- * int_handler --
- *
- * Handles Cntl-C interupts..
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
- void
- int_handler()
- {
- if (!quietFlag) {
- fprintf(stderr, "Interrupted!\n");
- }
- if (curVidStream != NULL)
- DestroyVidStream(curVidStream);
- exit(1);
- }
-
-
- /*
- *--------------------------------------------------------------
- *
- * main --
- *
- * Parses command line, starts decoding and displaying.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *--------------------------------------------------------------
- */
-
- void
- main(argc, argv)
- int argc;
- char **argv;
- {
-
- char *name;
- static VidStream *theStream;
- int mark;
- int i;
-
- mark = 1;
-
- name = "";
- input = stdin;
- ditherType = ORDERED2_DITHER;
- LUM_RANGE = 8;
- CR_RANGE = CB_RANGE = 4;
- noDisplayFlag = 0;
-
- #ifdef SH_MEM
- shmemFlag = 1;
- #endif
-
- printf("\n%s -- MPEG Analyzer for MPEG I video streams\n", argv[0]);
- if(argc > 2 ) {
- printf("Usage: %s [mpeg stream]\n", argv[0]);
- exit(1);
- }
-
- if(argc == 1)
- input = stdin;
- else {
- #ifdef DOS
- input = fopen(argv[1], "rb");
- #else
- input = fopen(argv[1], "r");
- #endif
- if (input == NULL) {
- fprintf(stderr, "Could not open file %s\n", argv[1]);
- exit (-1);
- }
- }
-
- printf("\nReading %s\n\n", argc == 1 ? "STDIN" : argv[1]);
-
- lum_values = (int *) malloc(LUM_RANGE*sizeof(int));
- cr_values = (int *) malloc(CR_RANGE*sizeof(int));
- cb_values = (int *) malloc(CB_RANGE*sizeof(int));
-
- signal(SIGINT, int_handler);
-
- init_tables();
-
- if (setjmp(env) != 0) {
-
- DestroyVidStream(theStream);
-
- rewind(input);
-
- EOF_flag = 0;
- curBits = 0;
- bitOffset = 0;
- bufLength = 0;
- bitBuffer = NULL;
- totNumFrames = 0;
- init_stats();
-
- }
-
- theStream = NewVidStream(BUF_LENGTH);
-
-
- mpegVidRsrc(0, theStream);
-
- if (ditherType == Twox2_DITHER) i = 2;
- else i = 1;
-
- realTimeStart = ReadSysClock();
-
- while (1) mpegVidRsrc(0, theStream);
- }
-
-